const BUILD = {
  data:{
    interval:null,
  },
  methods: {
    buildItem(data,type) {
      let defaultBuild = {
        newSdk:'y'
      }

      if(data.build[type]) return message({type:'error',message:'项目正在构建中，请稍后再试'})
      showDialog({
        title:'构建项目',
        content:`
        <div id='formBuild'>
          <div class="form-item">
            <label>构建类型: </label>
            <div style='width:400px;display:flex'>
            <label for='Android' ><input type="radio"  name='buildType' id='Android' value='Android' ${type == "Android" && 'checked'} /> Android</label>
            <label for='Ios' ><input type="radio"  name='buildType' id='Ios' value='Ios' ${type == "Ios" && 'checked'} /> iOS</label>
            <label for='wgt' ><input type="radio"  name='buildType' id='wgt' value='wgt' ${type == "wgt" && 'checked'} /> wgt热更新包</label>
            </div>
          </div>
          <div class="form-item">
            <label>是否使用最新打包cli: </label>
            <div style='width:300px;display:flex'>
            <label for='y' ><input type="radio" id='y' name='newSdk' value='y'  ${defaultBuild.newSdk == "y" && 'checked'} /> 检测sdk更新</label>
            <label for='n' ><input type="radio" id='n' name='newSdk' value='n'  ${defaultBuild.newSdk == "n" && 'checked'} /> 不检测</label>
            </div> 
          </div>
        </div>
        <div class="form-item flex-jc-ac">
          请确定是否构建项目:  ${data.projectName}<br/>
          项目构建时间较长，请耐心等待...
        </div>
      `,
        confirm:()=>{
          let type = document.querySelector('input[name="buildType"]:checked').value;
          let newSdk = document.querySelector('input[name="newSdk"]:checked').value;
          let pushData = {
            ...data,
            type,
            newSdk
          }
          fetchPost('/build',pushData).then(()=>{
            this.init()
            this.getStatus(pushData)
          })
          return true
        }
      })
    },
    getStatus(data){
      this.buildData.interval = setInterval(()=>{
        fetchGet('/build/getStatus',data).then((res)=>{ 
          if(res.status == 1){
            message({type:'success',message:'项目打包结束'+res.projectName})
            this.init()
            clearInterval(this.buildData.interval)
            this.buildData.interval = null;
          }else{
            if(!this.messageObj[this.acIndex]) this.messageObj[this.acIndex] = []
            this.messageObj[this.acIndex].push(
              dateFormat(new Date(), "yyyy-MM-dd hh:mm") + " : " + res.data
            );
          }
        })
      },5000)
    },
    
  },
  

}